﻿using System;
using System.Collections.Generic;
using System.Text;
using Terralever.Facebook.UI.FbmlControls;
using System.Web.UI.Design;

namespace Terralever.Facebook.UI.Design.FbmlControls
{
    public class FbNameDesigner : FbmlControlDesigner
    {
        public override string GetDesignTimeHtml()
        {
            if (Component == null)
                return base.GetDesignTimeHtml();

            Name nameControl = Component as Name;
            if (nameControl == null)
                return base.GetDesignTimeHtml();

            StringBuilder sb = new StringBuilder();
            if (nameControl.Linked)
            {
                sb.Append("<a href=\"#\">");
            }

            if (nameControl.UseYou)
            {
                if (nameControl.CapitalizeYou)
                    sb.Append("Y");
                else
                    sb.Append("y");

                sb.Append("ou");

                if (nameControl.Possessive || nameControl.Reflexive)
                {
                    sb.Append("r");
                    if (nameControl.Reflexive)
                        sb.Append("self");
                }
            }
            else
            {
                if (nameControl.FirstNameOnly)
                    sb.Append("Joe");
                else if (nameControl.LastNameOnly)
                    sb.Append("Smith");
                else
                    sb.Append("Joe Smith");

                if (nameControl.Possessive)
                    sb.Append("'s");
            }

            if (nameControl.ShowNetwork)
                sb.Append(" (Facebook Network");

            if (nameControl.Linked)
            {
                sb.Append("</a>");
            }

            return sb.ToString();
        }
    }
}
